package org.redhat.auth.security.core;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.security.access.ConfigAttribute;
import org.springframework.security.access.SecurityConfig;
import org.springframework.security.access.method.AbstractMethodSecurityMetadataSource;
import org.springframework.security.access.method.MethodSecurityMetadataSource;

public class AuthMethodMetadataSource extends
		AbstractMethodSecurityMetadataSource implements InitializingBean {
	
	private static Map<String, Collection<ConfigAttribute>> methodMap = null;

	public AuthMethodMetadataSource() {
		loadMethodResources();
	}

	private void loadMethodResources() {
		methodMap = new HashMap<String, Collection<ConfigAttribute>>();
		String methodUrl = "com.redhat.auth.application.impl.FunctionEntityTypeApplicationImpl.get";
		Collection<ConfigAttribute> atts = new ArrayList<ConfigAttribute>();
		ConfigAttribute ca = new SecurityConfig("ROLE_USER");
		atts.add(ca);
		methodMap.put(methodUrl, atts);

	}

	@Override
	public void afterPropertiesSet() throws Exception {
	}

	@Override
	public Collection<ConfigAttribute> getAttributes(Method method,
			Class<?> targetClass) {
		return methodMap
				.get("com.redhat.auth.application.impl.FunctionEntityTypeApplicationImpl.get");
	}

	@Override
	public Collection<ConfigAttribute> getAllConfigAttributes() {
		return methodMap
		.get("com.redhat.auth.application.impl.FunctionEntityTypeApplicationImpl.get");
	}
}
